package models

import (
	"gorm.io/gorm"
	"server/basic/config"
	"time"
)

type User struct {
	Id        uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Username  string         `gorm:"column:username;type:varchar(255);comment:用户名;not null;" json:"username"`  // 用户名
	Password  string         `gorm:"column:password;type:varchar(255);comment:密码;not null;" json:"password"`   // 密码
	Mobile    string         `gorm:"column:mobile;type:char(11);comment:手机号;not null;" json:"mobile"`          // 手机号
	Address   string         `gorm:"column:address;type:varchar(255);comment:地址;not null;" json:"address"`     // 地址
	Realname  string         `gorm:"column:realname;type:varchar(255);comment:真实姓名;not null;" json:"realname"` // 真实姓名
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}
func (u *User) CreateUser() error {
	return config.DB.Create(&u).Error
}
